package com.xn.app.muying.adpter;

import android.content.Context;
import android.content.Intent;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.xn.app.muying.R;
import com.xn.app.muying.activity.ChanJianXiangQingActivity;
import com.xn.app.muying.bean.ChanJianListBean;
import com.xn.app.muying.bean.ChanJianMessageBean;

import java.util.ArrayList;

/**
 * Created by Administrator on 2016/10/29.
 */
public class ChanJianListAdapter extends BaseAdapter {

    private LayoutInflater inflater;
    private Context context;
    private ArrayList<ChanJianListBean> list = new ArrayList<ChanJianListBean>();

    public ChanJianListAdapter(Context context, ArrayList list) {
        this.context = context;
        this.list = list;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {

        ViewHoler_GridView_List viewHoler_gridView = new ViewHoler_GridView_List();

        view = inflater.inflate(R.layout.item_gridview_check, null);
        viewHoler_gridView.tv_order = (TextView) view.findViewById(R.id.activity_chanjian_order);
        viewHoler_gridView.tv_time = (TextView) view.findViewById(R.id.activity_chanjian_time);
        viewHoler_gridView.ll = (LinearLayout) view.findViewById(R.id.activity_chanjian_ll);
        viewHoler_gridView.iv = (ImageView) view.findViewById(R.id.activity_chanjian_tubiao);

        if(list.get(i).getStatus().equals("0")){

            viewHoler_gridView.ll.setClickable(false);
            viewHoler_gridView.ll.setBackgroundResource(R.drawable.edit_white);

        }else if(list.get(i).getStatus().equals("1")){
            viewHoler_gridView.ll.setBackgroundResource(R.drawable.button_red);
            Resources resource = (Resources) context.getResources();
            ColorStateList csl = (ColorStateList) resource.getColorStateList(R.color.white);
            viewHoler_gridView.tv_order.setTextColor(csl);
            viewHoler_gridView.tv_time.setTextColor(csl);

            viewHoler_gridView.iv.setBackgroundResource(R.mipmap.img_11);

        }else if(list.get(i).getStatus().equals("2")){
            viewHoler_gridView.ll.setBackgroundResource(R.drawable.button_red);
            Resources resource = (Resources) context.getResources();
            ColorStateList csl = (ColorStateList) resource.getColorStateList(R.color.white);
            viewHoler_gridView.tv_order.setTextColor(csl);
            viewHoler_gridView.tv_time.setTextColor(csl);

            viewHoler_gridView.iv.setBackgroundResource(R.mipmap.img_12);

        }

        viewHoler_gridView.tv_order.setText("第"+list.get(i).getOrder()+"次");
        viewHoler_gridView.tv_time.setText(list.get(i).getStartWeek() + "周—" + list.get(i).getEndWeek()+"周");
        viewHoler_gridView.ll.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.putExtra("nextAntenatalCareId", list.get(i).getOrder());
                intent.setClass(context, ChanJianXiangQingActivity.class);
                context.startActivity(intent);
            }
        });

        return view;
    }


    class ViewHoler_GridView_List {
        TextView tv_order;
        TextView tv_time;
        LinearLayout ll;
        ImageView iv;
    }
}
